// pages/applicationForm/applicationForm.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navbarData: {
      showCapsule: 1, 
      title: '特邀买家俱乐部申请表', 
    },
    bgHeight:app.globalData.status+app.globalData.navHeight,
    switchChecked: true,
    companyAttr:['经销商/代理商/分销商','贸易公司','建筑/工程总包商','地产商','设计公司、设计师','家装公司','其他'],
    companyIndex:0,
    companyValue:'请选择',
    needBrand:['国内','国际','无要求'],
    needIndex:0,
    needValue:'请选择',
    brandRequire:['一线','二线','无要求'],
    requireIndex:0,
    requireValue:'请选择',
    purchaseAmount:['50万~80万','80万~150万','150万以上'],
    amountIndex:0,
    amountValue:'请选择',
    productApply:['学校','办公楼','其他'],
    applyIndex:0,
    applyValue:'请选择',
    isShowCate:false,
    purchaseCate:'请选择',
    cateList:[
      {id: 1,  name: '手工地毯/块毯'},
      {id: 2,  name: '机制地毯/地垫'},
      {id: 3,  name: '纤维、纱线、地毯原辅材料'},
      {id: 4,  name: '实木地板'},
      {id: 5,  name: '实木复合地板'},
      {id: 6,  name: '强化地板'},
      {id: 7,  name: '软木地板'},
      {id: 8,  name: '竹地板'},
      {id: 9,  name: '运动地材'},
      {id: 10,  name: 'PVC卷材地板(同质透心/复合卷材)'},
      {id: 11,  name: '石晶地板/石塑地板'},
      {id: 12,  name: '豪华商用片材'},
      {id: 13,  name: '室内木塑地板'},
      {id: 14,  name: '室外木塑地板'},
      {id: 15,  name: '人造草坪'},
      {id: 16,  name: '橡胶地板'},
      {id: 17,  name: '亚麻地板'},
      {id: 18,  name: '防静电地板'},
      {id: 19,  name: '地毯生产技术及配件'},
      {id: 20,  name: '地坪'},
      {id: 21,  name: '地毯安装技术'},
      {id: 22,  name: '地毯清洁维护技术'},
      {id: 23,  name: '实木地板生产技术'}
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  switchChange(){
    this.setData({
      switchChecked:!this.data.switchChecked
    })
  },
  bindCompanyAttrChange(e){
    this.setData({
      companyIndex: e.detail.value,
      companyValue:this.data.companyAttr[e.detail.value]
    })
  },
  bindNeedBrandChange(e){
    this.setData({
      needIndex: e.detail.value,
      needValue:this.data.needBrand[e.detail.value]
    })
  },
  bindBrandRequireChange(e){
    this.setData({
      requireIndex: e.detail.value,
      requireValue:this.data.brandRequire[e.detail.value]
    })
  },
  bindPurchaseAmountChange(e){
    this.setData({
      amountIndex: e.detail.value,
      amountValue:this.data.purchaseAmount[e.detail.value]
    })
  },
  bindProductApplyChange(e){
    this.setData({
      applyIndex: e.detail.value,
      applyValue:this.data.productApply[e.detail.value]
    })
  },
  showCate(){
    this.setData({
      isShowCate:!this.data.isShowCate
    })
  },
  checkboxChange(e){
    const cateList = this.data.cateList
    const values = e.detail.value
    for (let i = 0, lenI = cateList.length; i < lenI; ++i) {
      cateList[i].checked = false
      for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
        if (cateList[i].name === values[j]) {
          cateList[i].checked = true
          break
        }
      }
    }
    this.setData({
      cateList
    })
  },
  cancel(){
    this.setData({
      isShowCate:false
    })
  },
  checkConfirm(){
    var selected = [];//当前选择到的值
    const cateList = this.data.cateList
    for(var i=0; i<cateList.length;i++){
        if(cateList[i].checked == true){
          selected.push(cateList[i].name);
        }
    }
    let purchaseCate=selected.toString();
    this.setData({
      purchaseCate:purchaseCate,
      isShowCate:false
    })
  }
})